package com.dg11185.nearshop.net.response;

import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.nearshop.net.entity.MerchantInfo;

public class GetMerchantInfoResponse {
    public NetStatus status = null;

    public MerchantInfo merchant = null;

    public GetMerchantInfoResponse() {
        merchant = new MerchantInfo();
    }

    public void parseJson(String response) {
        try {
            JSONObject object = new JSONObject(response);
            status = NetStatus.getStatus(object.optString("status"));
            if (!object.isNull("merchant")) {
                JSONObject merchantObject = object.optJSONObject("merchant");

                merchant.merchantId = merchantObject.optString("merchantId");
                merchant.merchantName = merchantObject.optString("merchantName");
                merchant.address = merchantObject.optString("address");
                merchant.areaNum = merchantObject.optString("areaNum");
                merchant.longitude = merchantObject.optString("longitude");
                merchant.latitude = merchantObject.optString("latitude");
//                if (!"".equals(merchant.latitude) && !"".equals(merchant.longitude)) {
//                    String[] point = ConvertUnit.convertGeopoint(merchant.latitude, merchant.longitude);
//                    merchant.latitude = point[0];
//                    merchant.longitude = point[1];
//                }
                merchant.telephone = merchantObject.optString("telephone");
                merchant.oriPhotoURL = merchantObject.optString("oriPhotoURL");
                merchant.minPhotoUrl = merchantObject.optString("minPhotoUrl");
                merchant.midPhotoUrl = merchantObject.optString("midPhotoUrl");
                merchant.maxPhotoUrl = merchantObject.optString("maxPhotoUrl");
                merchant.description = merchantObject.optString("description");
                merchant.discountMsg = merchantObject.optString("discountMsg");
                merchant.preferentialType = merchantObject.optString("preferentialType");
                merchant.preferential = merchantObject.optString("preferential");
                merchant.avgPrice = merchantObject.optString("avgPrice");
                merchant.workTime = merchantObject.optString("workTime");
                merchant.createTime = merchantObject.optString("createTime");
                merchant.updateTime = merchantObject.optString("updateTime");
                merchant.industryId = merchantObject.optString("industryId");
                merchant.industryName = merchantObject.optString("industryName");
                merchant.brandId = merchantObject.optString("brandId");
                merchant.isDayMer = merchantObject.optString("isDayMer");
            }

            if (!object.isNull("merchantStats")) {
                JSONObject merchantStats = object.optJSONObject("merchantStats");
                merchant.avgRating = merchantStats.optString("avgRating");
                merchant.totalLikes = merchantStats.optString("totalLikes");
                merchant.totalComments = merchantStats.optString("totalComments");
                merchant.totalFavors = merchantStats.optString("totalFavors");
            }
            if (!object.isNull("userBehavior")) {
                JSONObject merchantStats = object.optJSONObject("userBehavior");
                merchant.isLike = merchantStats.optString("isLike");
                merchant.isFavor = merchantStats.optString("isFavor");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

}
